<template>
  <el-autocomplete
    v-model="value"
    :fetch-suggestions="querySearchAsync"
    placeholder="请输入分组名称"
    style="width: 100%"
    @input="handleInput"
  />
</template>

<script>
import { search } from '@/api/business/common/org/tag'

export default {
  name: 'OrgTagGroupSuggest',
  props: {
    name: {
      type: String,
      required: false,
      default: ''
    }
  },
  data() {
    return {
      value: ''
    }
  },
  mounted() {
    this.value = this.name
  },
  methods: {
    querySearchAsync(queryString, cb) {
      search(queryString).then((data) => {
        const itemValues = []
        if (data.length > 0) {
          data.forEach(item => {
            itemValues.push({ value: item, key: item })
          })
        }
        cb(itemValues)
      })
    },
    handleInput(value) {
      this.$emit('input', value)
    }
  }
}
</script>

<style scoped>

</style>
